﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.CodeDom;

namespace CodeDomHelper.CodeDom
{
    public class RegionExp : IDisposable
    {

        Action End;



        public RegionExp(CodeStatement statment, string regionText)
        {
            RegionText = regionText;
            statment.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, regionText));
            End = () => statment.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, regionText));
        }

        public RegionExp(CodeCompileUnit statment, string regionText)
        {
            RegionText = regionText;
            statment.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, regionText));
            End = () => statment.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, regionText));
        }

        public void Dispose()
        {
            End();
        }

        public string RegionText { get; set; }

    }

}
